using System.Collections.Generic;

namespace Framework
{
    public abstract class Composite<T> : Behavior<T>
    {
        protected List<Behavior<T>> _children = new List<Behavior<T>>();
        protected int _currentChildIndex = 0;
            
        public override void Invalidate()
        {
            base.Invalidate();
            int count = _children.Count;
            for (int i = 0; i < count; ++i)
            {
                _children[i].Invalidate();
            }
        }

        public override void OnStart(T context)
        {
            base.OnStart(context);
            _currentChildIndex = 0;
        }

        public override void OnEnd(T context)
        {
            base.OnEnd(context);
            int count = _children.Count;
            for (int i = 0; i < count; ++i)
            {
                _children[i].Invalidate();
            }
        }
        
        public void AddChild(Behavior<T> child)
        {
            _children.Add(child);
        }
    }
}